home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / RCP.jar / com / extensibility / app / ApplicationPreferences.class (.txt) next >
Encoding:
Java Class File  |  2000-08-03  |  10.7 KB  |  538 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.plugin.api.PrintPreferences;
  4. import com.extensibility.util.Debug;
  5. import com.extensibility.xml.URI;
  6. import java.awt.Component;
  7. import java.awt.Font;
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.FileNotFoundException;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import java.io.OutputStream;
  14. import java.util.Enumeration;
  15. import java.util.Hashtable;
  16. import java.util.Properties;
  17. import java.util.Vector;
  18.  
  19. public class ApplicationPreferences extends Properties {
  20.    public static final String PREF_FILENAME = "_Preferences";
  21.    public static final String RECENT = "RECENT.";
  22.    public static final String RECENT_1 = "RECENT.1";
  23.    public static final String RECENT_2 = "RECENT.2";
  24.    public static final String RECENT_3 = "RECENT.3";
  25.    public static final String RECENT_4 = "RECENT.4";
  26.    public static final String RECENT_5 = "RECENT.5";
  27.    public static final String PLATFORM = "os.name";
  28.    public static final String MACOS = "Mac";
  29.    public static final String USER_NAME_CODE = "ESB";
  30.    public static final String ORGANIZATION_CODE = "KKB";
  31.    public static final String EMAIL_CODE = "EMC";
  32.    public static final String PHONE_CODE = "PHC";
  33.    public static final String SN_CODE = "CAB";
  34.    public static final String LAUNCHES_LEFT = "EGB";
  35.    public static final String REG_SENT = "RGS";
  36.    public static final String OEM_PARTNER_KEY = "OEM";
  37.    public static final String TOOLBAR_VIEW = "TOOLBAR.VIEW";
  38.    public static final String ONLINE_HELP = "ONLINE.HELP";
  39.    public static final String EXTERNAL_HELP_BROWSER = "EXTERNAL.HELP.BROWSER";
  40.    public static final String SHOW_WELCOME = "SHOW.WELCOME";
  41.    public static final String SHOW_LEFT_PANE = "SHOW.PANE.LEFT";
  42.    public static final String SHOW_BOTTOM_PANE = "SHOW.PANE.BOTTOM";
  43.    public static final String LOOK_AND_FEEL = "LOOK.AND.FEEL";
  44.    public static final String DEBUG_LEVEL = "DEBUG.LEVEL";
  45.    public static final String BROWSER_PATH = "BROWSER.PATH";
  46.    public static final String INTEGRATION_PORT = "INTEGRATION.PORT";
  47.    public static final String OPEN_FROM_BASE = "OPEN.FROM.BASE";
  48.    public static final String SAVE_TO_BASE = "SAVE.TO.BASE";
  49.    public static final String APP_FONT = "APP.FONT";
  50.    public static final String DOC_FONT = "DOC.FONT";
  51.    public static final String SRC_FONT = "SRC.FONT";
  52.    public static final String LEFT_MARGIN = "MARGIN.LEFT";
  53.    public static final String RIGHT_MARGIN = "MARGIN.RIGHT";
  54.    public static final String TOP_MARGIN = "MARGIN.TOP";
  55.    public static final String BOTTOM_MARGIN = "MARGIN.BOTTOM";
  56.    public static final String PRINT_PREF_ORIENTATION = "PRINT.PREF.ORIENTATION";
  57.    public static final String PRINT_PREF_WIDTH = "PRINT.PREF.WIDTH";
  58.    public static final String PRINT_PREF_HEIGHT = "PRINT.PREF.HEIGHT";
  59.    public static final String PRINT_PREF_IMAGEABLE_X = "PRINT.PREF.IMAGEABLE.X";
  60.    public static final String PRINT_PREF_IMAGEABLE_Y = "PRINT.PREF.IMAGEABLE.Y";
  61.    public static final String PRINT_PREF_IMAGEABLE_WIDTH = "PRINT.PREF.IMAGEABLE.WIDTH";
  62.    public static final String PRINT_PREF_IMAGEABLE_HEIGHT = "PRINT.PREF.IMAGEABLE.HEIGHT";
  63.    public static final String NUMS = "NUMS";
  64.    public static final String TRUE = "TRUE";
  65.    public static final String FALSE = "FALSE";
  66.    public static final String ASK = "ASK";
  67.    private static final int[] LAUNCH_CODES = new int[]{17054, 17296, 15217, 18688, 13450, 13015, 14645, 13151, 14322, 10118, 16682, 19513, 10317, 19393, 19578, 11150, 16933, 17466, 14093, 13906, 12261, 13193, 14278, 13754, 14009, 16575, 10757, 16949, 19035, 10161, 16504, 12686, 15379, 12956, 15133, 18256, 16795, 16826, 11671, 16703, 19780, 15404, 15842, 16975, 13106, 15497, 17849, 16589, 19852, 10993, 16657, 16781, 11936, 19265, 10768, 10163, 17143, 10081, 11509, 10882, 18661, 17003, 18810, 17272, 17108, 11304, 19485, 17017, 15065, 18363, 18015, 14798, 14108, 16581, 19828, 12457, 14336, 18780, 17080, 11651, 16407, 16114, 16938, 19004, 16067, 14471, 12358, 13772, 11180, 13383, 15370, 15370};
  68.    public static final String SOX_SCHEMA_PATH = "SOX.SCHEMA.PATH";
  69.    static File file;
  70.    public static final String DEFAULT_FILE_TYPE = "DEFAULT.FILE.TYPE";
  71.  
  72.    public void readInitial(File var1) {
  73.       FileInputStream var2 = null;
  74.  
  75.       try {
  76.          if (file == null) {
  77.             file = var1;
  78.          }
  79.  
  80.          var2 = new FileInputStream(file);
  81.          ((Properties)this).load(var2);
  82.          var2.close();
  83.       } catch (FileNotFoundException var5) {
  84.          this.initialize();
  85.       } catch (IOException var6) {
  86.          DialogFactory.showException((Component)null, 121, var6);
  87.          this.initialize();
  88.          if (var2 != null) {
  89.             try {
  90.                var2.close();
  91.             } catch (IOException var4) {
  92.             }
  93.          }
  94.       }
  95.  
  96.    }
  97.  
  98.    private void initialize() {
  99.       ((Hashtable)this).put("RECENT.1", "");
  100.       ((Hashtable)this).put("RECENT.2", "");
  101.       ((Hashtable)this).put("RECENT.3", "");
  102.       ((Hashtable)this).put("RECENT.4", "");
  103.       ((Hashtable)this).put("RECENT.5", "");
  104.       ((Hashtable)this).put("ESB", "");
  105.       ((Hashtable)this).put("KKB", "");
  106.       ((Hashtable)this).put("CAB", "");
  107.       ((Hashtable)this).put("SHOW.WELCOME", "TRUE");
  108.       ((Hashtable)this).put("ONLINE.HELP", "TRUE");
  109.  
  110.       try {
  111.          this.save();
  112.       } catch (IOException var2) {
  113.          ((Throwable)var2).printStackTrace();
  114.          DialogFactory.showException((Component)null, 108, var2);
  115.       }
  116.  
  117.    }
  118.  
  119.    public void save() throws IOException {
  120.       FileOutputStream var1 = null;
  121.  
  122.       try {
  123.          var1 = new FileOutputStream(file);
  124.          ((Properties)this).save(var1, UI.getString("splash.title") + " preferences");
  125.       } finally {
  126.          if (var1 != null) {
  127.             ((OutputStream)var1).close();
  128.          }
  129.  
  130.       }
  131.  
  132.    }
  133.  
  134.    public String getLookAndFeel() {
  135.       String var1 = ((Properties)this).getProperty("LOOK.AND.FEEL");
  136.       if (var1 == null) {
  137.          String var2 = System.getProperty("os.name");
  138.          return var2.startsWith("Mac") ? "it.unitn.ing.swing.plaf.macos.MacOSLookAndFeel" : "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  139.       } else {
  140.          return var1;
  141.       }
  142.    }
  143.  
  144.    public void updateLookAndFeel(String var1) {
  145.       ((Hashtable)this).put("LOOK.AND.FEEL", var1);
  146.    }
  147.  
  148.    public Font getAppFont() {
  149.       String var1 = (String)((Hashtable)this).get("APP.FONT");
  150.       return var1 == null ? new Font("SansSerif", 0, 11) : Font.decode(var1);
  151.    }
  152.  
  153.    public void updateAppFont(Font var1) {
  154.       ((Hashtable)this).put("APP.FONT", var1.getName() + "-" + var1.getSize());
  155.    }
  156.  
  157.    public Font getDocFont() {
  158.       String var1 = (String)((Hashtable)this).get("DOC.FONT");
  159.       return var1 == null ? null : Font.decode(var1);
  160.    }
  161.  
  162.    public void updateDocFont(Font var1) {
  163.       ((Hashtable)this).put("DOC.FONT", var1.getName() + "-" + var1.getSize());
  164.    }
  165.  
  166.    public void updateDocFont(int var1) {
  167.       if (var1 == -1) {
  168.          ((Hashtable)this).remove("DOC.FONT");
  169.       } else {
  170.          Font var2 = this.getDocFont();
  171.          String var3 = var2 == null ? "SansSerif" : var2.getName();
  172.          ((Hashtable)this).put("DOC.FONT", var3 + "-" + var1);
  173.       }
  174.  
  175.    }
  176.  
  177.    public void updateDocFont(String var1, int var2) {
  178.       if (var1 == null) {
  179.          var1 = "SansSerif";
  180.       }
  181.  
  182.       if (var2 == -1) {
  183.          ((Hashtable)this).put("DOC.FONT", var1);
  184.       } else {
  185.          ((Hashtable)this).put("DOC.FONT", var1 + "-" + var2);
  186.       }
  187.  
  188.    }
  189.  
  190.    public void updateSrcFont(String var1, int var2) {
  191.       if (var1 == null) {
  192.          var1 = "SansSerif";
  193.       }
  194.  
  195.       if (var2 == -1) {
  196.          ((Hashtable)this).put("SRC.FONT", var1);
  197.       } else {
  198.          ((Hashtable)this).put("SRC.FONT", var1 + "-" + var2);
  199.       }
  200.  
  201.    }
  202.  
  203.    public Font getSrcFont() {
  204.       String var1 = (String)((Hashtable)this).get("SRC.FONT");
  205.       return var1 == null ? null : Font.decode(var1);
  206.    }
  207.  
  208.    public void updateSrcFont(Font var1) {
  209.       ((Hashtable)this).put("SRC.FONT", var1.getName() + "-" + var1.getSize());
  210.    }
  211.  
  212.    public int getLaunchesLeft() {
  213.       String var1 = ((Properties)this).getProperty("EGB");
  214.       if (var1 == null) {
  215.          return 0;
  216.       } else {
  217.          int var2 = Integer.valueOf(var1);
  218.  
  219.          for(int var3 = 0; var3 < LAUNCH_CODES.length; ++var3) {
  220.             if (LAUNCH_CODES[var3] == var2) {
  221.                return var3;
  222.             }
  223.          }
  224.  
  225.          return 0;
  226.       }
  227.    }
  228.  
  229.    public void updateLaunchesLeft(int var1) {
  230.       Debug.assert(var1 >= 0 && var1 < LAUNCH_CODES.length, "invalid newLeft: " + var1);
  231.       ((Hashtable)this).put("EGB", (new Integer(LAUNCH_CODES[var1])).toString());
  232.  
  233.       try {
  234.          this.save();
  235.       } catch (Exception var2) {
  236.       }
  237.  
  238.    }
  239.  
  240.    public void initTrialLaunchesLeft(int var1) {
  241.       ((Hashtable)this).put("EGB", (new Integer(LAUNCH_CODES[var1])).toString());
  242.    }
  243.  
  244.    public boolean getOnlineHelp() {
  245.       String var1 = ((Properties)this).getProperty("ONLINE.HELP");
  246.       return var1 == null ? false : Boolean.valueOf(var1);
  247.    }
  248.  
  249.    public void updateOnlineHelp(boolean var1) {
  250.       ((Hashtable)this).put("ONLINE.HELP", (new Boolean(var1)).toString());
  251.    }
  252.  
  253.    public boolean getExternalHelpBrowser() {
  254.       String var1 = ((Properties)this).getProperty("EXTERNAL.HELP.BROWSER");
  255.       return var1 == null ? false : Boolean.valueOf(var1);
  256.    }
  257.  
  258.    public void updateExternalHelpBrowser(boolean var1) {
  259.       ((Hashtable)this).put("EXTERNAL.HELP.BROWSER", (new Boolean(var1)).toString());
  260.    }
  261.  
  262.    public boolean getShowWelcome() {
  263.       String var1 = ((Properties)this).getProperty("SHOW.WELCOME");
  264.       return var1 == null ? true : Boolean.valueOf(var1);
  265.    }
  266.  
  267.    public void updateShowWelcome(boolean var1) {
  268.       ((Hashtable)this).put("SHOW.WELCOME", (new Boolean(var1)).toString());
  269.    }
  270.  
  271.    public boolean getShowLeftPane() {
  272.       String var1 = ((Properties)this).getProperty("SHOW.PANE.LEFT");
  273.       return var1 == null ? false : Boolean.valueOf(var1);
  274.    }
  275.  
  276.    public void updateShowLeftPane(boolean var1) {
  277.       ((Hashtable)this).put("SHOW.PANE.LEFT", (new Boolean(var1)).toString());
  278.    }
  279.  
  280.    public boolean getShowBottomPane() {
  281.       String var1 = ((Properties)this).getProperty("SHOW.PANE.BOTTOM");
  282.       return var1 == null ? false : Boolean.valueOf(var1);
  283.    }
  284.  
  285.    public void updateShowBottomPane(boolean var1) {
  286.       ((Hashtable)this).put("SHOW.PANE.BOTTOM", (new Boolean(var1)).toString());
  287.    }
  288.  
  289.    public String[] getMargins() {
  290.       String[] var1 = new String[4];
  291.       String var2 = ((Properties)this).getProperty("MARGIN.LEFT");
  292.       if (var2 == null) {
  293.          var1[2] = "60";
  294.       } else {
  295.          var1[2] = var2;
  296.       }
  297.  
  298.       String var3 = ((Properties)this).getProperty("MARGIN.RIGHT");
  299.       if (var3 == null) {
  300.          var1[3] = "60";
  301.       } else {
  302.          var1[3] = var3;
  303.       }
  304.  
  305.       String var4 = ((Properties)this).getProperty("MARGIN.TOP");
  306.       if (var4 == null) {
  307.          var1[0] = "60";
  308.       } else {
  309.          var1[0] = var4;
  310.       }
  311.  
  312.       String var5 = ((Properties)this).getProperty("MARGIN.BOTTOM");
  313.       if (var5 == null) {
  314.          var1[1] = "60";
  315.       } else {
  316.          var1[1] = var5;
  317.       }
  318.  
  319.       return var1;
  320.    }
  321.  
  322.    public PrintPreferences getPrintPreferences() {
  323.       PrintPreferences var1 = new PrintPreferences();
  324.       String var2 = ((Properties)this).getProperty("PRINT.PREF.ORIENTATION");
  325.       String var3 = ((Properties)this).getProperty("PRINT.PREF.WIDTH");
  326.       String var4 = ((Properties)this).getProperty("PRINT.PREF.HEIGHT");
  327.       String var5 = ((Properties)this).getProperty("PRINT.PREF.IMAGEABLE.X");
  328.       String var6 = ((Properties)this).getProperty("PRINT.PREF.IMAGEABLE.Y");
  329.       String var7 = ((Properties)this).getProperty("PRINT.PREF.IMAGEABLE.WIDTH");
  330.       String var8 = ((Properties)this).getProperty("PRINT.PREF.IMAGEABLE.HEIGHT");
  331.       if (var2 == null) {
  332.          var2 = Integer.toString(1);
  333.       }
  334.  
  335.       if (var3 == null) {
  336.          var3 = Double.toString((double)612.0F);
  337.       }
  338.  
  339.       if (var4 == null) {
  340.          var4 = Double.toString((double)792.0F);
  341.       }
  342.  
  343.       if (var5 == null) {
  344.          var5 = Double.toString((double)72.0F);
  345.       }
  346.  
  347.       if (var6 == null) {
  348.          var6 = Double.toString((double)72.0F);
  349.       }
  350.  
  351.       if (var7 == null) {
  352.          var7 = Double.toString((double)468.0F);
  353.       }
  354.  
  355.       if (var8 == null) {
  356.          var8 = Double.toString((double)648.0F);
  357.       }
  358.  
  359.       var1.setOrientation(Integer.parseInt(var2));
  360.       var1.setWidth(Double.valueOf(var3));
  361.       var1.setHeight(Double.valueOf(var4));
  362.       var1.setImageableX(Double.valueOf(var5));
  363.       var1.setImageableY(Double.valueOf(var6));
  364.       var1.setImageableWidth(Double.valueOf(var7));
  365.       var1.setImageableHeight(Double.valueOf(var8));
  366.       return var1;
  367.    }
  368.  
  369.    public int getDebugLevel() {
  370.       String var1 = (String)((Hashtable)this).get("DEBUG.LEVEL");
  371.       if (var1 == null) {
  372.          return 0;
  373.       } else {
  374.          int var2 = Integer.valueOf(var1);
  375.          return var2;
  376.       }
  377.    }
  378.  
  379.    public String getBrowserPath() {
  380.       String var1 = (String)((Hashtable)this).get("BROWSER.PATH");
  381.       return var1;
  382.    }
  383.  
  384.    public String getOpenFromBase() {
  385.       String var1 = (String)((Hashtable)this).get("OPEN.FROM.BASE");
  386.       return var1;
  387.    }
  388.  
  389.    public void updateOpenFromBase(String var1) {
  390.       ((Hashtable)this).put("OPEN.FROM.BASE", var1);
  391.    }
  392.  
  393.    public String getSaveToBase() {
  394.       String var1 = (String)((Hashtable)this).get("SAVE.TO.BASE");
  395.       return var1;
  396.    }
  397.  
  398.    public void updateSaveToBase(String var1) {
  399.       ((Hashtable)this).put("SAVE.TO.BASE", var1);
  400.    }
  401.  
  402.    public void updateDebugLevel(int var1) {
  403.       ((Hashtable)this).put("DEBUG.LEVEL", (new Integer(var1)).toString());
  404.    }
  405.  
  406.    public void updateBrowserPath(String var1) {
  407.       if (var1 != null && var1.length() != 0) {
  408.          ((Hashtable)this).put("BROWSER.PATH", var1);
  409.       } else {
  410.          ((Hashtable)this).remove("BROWSER.PATH");
  411.       }
  412.  
  413.    }
  414.  
  415.    public void updateMargins(String[] var1) {
  416.       ((Hashtable)this).put("MARGIN.LEFT", var1[2]);
  417.       ((Hashtable)this).put("MARGIN.RIGHT", var1[3]);
  418.       ((Hashtable)this).put("MARGIN.TOP", var1[0]);
  419.       ((Hashtable)this).put("MARGIN.BOTTOM", var1[1]);
  420.    }
  421.  
  422.    public void updatePrintPreferences(PrintPreferences var1) {
  423.       ((Hashtable)this).put("PRINT.PREF.ORIENTATION", Integer.toString(var1.getOrientation()));
  424.       ((Hashtable)this).put("PRINT.PREF.WIDTH", Double.toString(var1.getWidth()));
  425.       ((Hashtable)this).put("PRINT.PREF.HEIGHT", Double.toString(var1.getHeight()));
  426.       ((Hashtable)this).put("PRINT.PREF.IMAGEABLE.X", Double.toString(var1.getImageableX()));
  427.       ((Hashtable)this).put("PRINT.PREF.IMAGEABLE.Y", Double.toString(var1.getImageableY()));
  428.       ((Hashtable)this).put("PRINT.PREF.IMAGEABLE.WIDTH", Double.toString(var1.getImageableWidth()));
  429.       ((Hashtable)this).put("PRINT.PREF.IMAGEABLE.HEIGHT", Double.toString(var1.getImageableHeight()));
  430.    }
  431.  
  432.    public int getToolbarView() {
  433.       String var1 = ((Properties)this).getProperty("TOOLBAR.VIEW");
  434.       return var1 == null ? 1 : Integer.parseInt(var1);
  435.    }
  436.  
  437.    public void updateToolBarView(int var1) {
  438.       ((Hashtable)this).put("TOOLBAR.VIEW", (new Integer(var1)).toString());
  439.    }
  440.  
  441.    public void removeFromRecent(URI var1) {
  442.       String var2 = var1.getFullName();
  443.  
  444.       for(int var3 = 1; var3 <= 5; ++var3) {
  445.          String var4 = ((Properties)this).getProperty("RECENT." + var3);
  446.          if (var4 != null && var4.equals(var2)) {
  447.             ((Hashtable)this).remove("RECENT." + var3);
  448.             break;
  449.          }
  450.       }
  451.  
  452.       Vector var9 = new Vector();
  453.  
  454.       for(int var5 = 1; var5 <= 5; ++var5) {
  455.          String var6 = ((Properties)this).getProperty("RECENT." + var5);
  456.          if (var6 != null) {
  457.             var9.addElement(var6);
  458.             ((Hashtable)this).remove("RECENT." + var5);
  459.          }
  460.       }
  461.  
  462.       int var10 = 1;
  463.       Enumeration var7 = var9.elements();
  464.  
  465.       while(var7.hasMoreElements()) {
  466.          ((Hashtable)this).put("RECENT." + var10++, (String)var7.nextElement());
  467.       }
  468.  
  469.       try {
  470.          this.save();
  471.       } catch (Exception var8) {
  472.       }
  473.  
  474.    }
  475.  
  476.    public void updateRecent(String var1, URI var2) {
  477.       String var4 = var2.getFullName();
  478.       if (var4 != null && !var4.equals("")) {
  479.          int var3;
  480.          for(var3 = 5; var3 > 0; --var3) {
  481.             String var5 = ((Properties)this).getProperty(var1 + var3);
  482.             if (var5 != null && var5.equals(var4)) {
  483.                return;
  484.             }
  485.          }
  486.  
  487.          if (var3 == 0) {
  488.             for(int var9 = 5; var9 > 1; --var9) {
  489.                String var6 = ((Properties)this).getProperty(var1 + (var9 - 1));
  490.                if (var6 != null) {
  491.                   ((Hashtable)this).put(var1 + var9, var6);
  492.                }
  493.             }
  494.  
  495.             var3 = 1;
  496.          }
  497.  
  498.          ((Hashtable)this).put(var1 + 1, var4);
  499.  
  500.          try {
  501.             this.save();
  502.          } catch (Exception var7) {
  503.          }
  504.  
  505.       }
  506.    }
  507.  
  508.    public void updateRecent(URI var1) {
  509.       this.updateRecent("RECENT.", var1);
  510.    }
  511.  
  512.    public String getDefaultFileType() {
  513.       String var1 = (String)((Hashtable)this).get("DEFAULT.FILE.TYPE");
  514.       if (var1 == null) {
  515.          var1 = UI.getString("com.extensibility.app.defaultfiletype");
  516.       }
  517.  
  518.       return var1;
  519.    }
  520.  
  521.    public void updateDefaultFileType(String var1) {
  522.       ((Hashtable)this).put("DEFAULT.FILE.TYPE", var1);
  523.    }
  524.  
  525.    public String getSchemaPath() {
  526.       String var1 = (String)((Hashtable)this).get("SOX.SCHEMA.PATH");
  527.       return var1;
  528.    }
  529.  
  530.    public void updateSchemaPath(String var1) {
  531.       ((Hashtable)this).put("SOX.SCHEMA.PATH", var1);
  532.    }
  533.  
  534.    public void setGeneralPreference(String var1, String var2) {
  535.       ((Hashtable)this).put(var1, var2);
  536.    }
  537. }
  538.